<?php 

/*
* IndexController implements
*/
class  MainController extends Controller{

	public function __construct($controllerName,$action){
		parent::__construct($controllerName,$action);	
	}	
	
	/*
	* IndexAction 
	*/
	public function IndexAction(){
		$this->view->Render();
	}

	/*
	* SaveAction
	*/
	public function AddAction(){
		$questionare = new QuestionareDTO();
		
		foreach($questionare->GetAnswers() as $key =>  $value){		
			$questionare->$key = Request::GetParamValueByPost($key);
			if($key != 'question_10' && !is_numeric($questionare->$key))	
				die('Fatal Error: wrong received data!');
		}			

		$questionare->SetUserName(Request::GetParamValueByPost('username'));
		$questionare->SetEmail(Request::GetParamValueByPost('email'));
		
		try{
			$this->model->Save($questionare);
			$this->view->Render();

		}catch(PDOException $e){
			die("Error connect with database!");
		}

	}
}

?>
